<template>
    <div class="name-box">
        <el-card>
            <el-button type="info" size="mini" icon="el-icon-arrow-left">
                返回</el-button>
            <el-form label-position="top" label-width="80px" >
                <el-row :gutter="20">
                    <el-col :span="24">
                        <el-form-item>
                            <span slot="label">
                                <span class="label-text">步骤名称</span>

                            </span>
                            <el-input v-model="myData.name"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span slot="label">
                                <span class="label-text">步骤排序</span>

                            </span>
                            <el-input v-model="myData.sort"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span slot="label">
                                <span class="label-text">审批人</span>
                            </span>
                            <el-input v-model="myData.Approver">
                                <el-button slot="suffix" icon="el-icon-plus" type="success" size="mini"
                                    @click="dialogVisible = true">新增</el-button>
                            </el-input>
                        </el-form-item>
                        <el-checkbox v-model="myData.countersign" class="label-text">会签</el-checkbox>
                    </el-col>

                </el-row>
                <el-form-item class="sub-btn">
                    <el-button type="primary" @click="stepSave">保存</el-button>
                    <el-button>取消</el-button>
                </el-form-item>

            </el-form>
            <el-dialog :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
                <div class="search">
                    <div style="display: flex;">
                        <el-button type="success" icon="el-icon-plus" size="mini"
                            @click="addApprover">新增审批人</el-button>
                        <el-button type="success" icon="el-icon-plus" size="mini"
                            >追加审批人</el-button>

                    </div>
                    <div class="search-box">
                        <el-input  placeholder="查找..." size="mini">
                            <el-button type="success" icon="el-icon-search" slot="append"></el-button>
                        </el-input>
                    </div>
                </div>
                <el-table :data="currentPageData" style="width: 100%" :default-sort="{ prop: 'date', order: 'descending' }"
                    tooltip-effect="dark" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column prop="depName" label="部门" sortable width="180">
                    </el-table-column>
                    <el-table-column prop="name" label="真实姓名" sortable width="180">
                    </el-table-column>
                    <el-table-column prop="yhName" label="用户名" sortable></el-table-column>
                    <el-table-column prop="role" label="角色" sortable></el-table-column>
                    <el-table-column prop="tel" label="电话"></el-table-column>
                </el-table>
                <pager :page=page :limit=limit :total=total :lastPage=lastPage @handleSizeChange="handleSizeChange"
                    @toLastPage="toLastPage" @toFirstPage="toFirstPage" @handleCurrentChange="handleCurrentChange"></pager>
            </el-dialog>

        </el-card>
    </div>
</template>

<script>
import pager from "@/views/WorkFlow/TemManage/components/Stepedit/pager.vue";
export default {
    name: "nameBox",
    data() {
        return {
            myData: {
                name: '',
                sort: '',
                Approver: '',
                countersign: false,
            },
            multipleSelection:"",
            dialogVisible: false,
            page: 1,
            limit: 3,
            lastPage: 0,
            total: 0,
            currentPageData: [], //当前页显示内容
            tableData: [],


        }
    },
    components: {
        
        pager

    },
    methods: {
        handleClose() {
            this.dialogVisible = false
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        handleSizeChange(val) {
            this.limit = val;
            this.lastPage = Math.ceil(this.tableData.length / this.limit);
            this.getCurrentPageData()
        },
        getCurrentPageData() {
            let begin = (this.page - 1) * this.limit;
            let end = this.page * this.limit;
            this.currentPageData = this.tableData.slice(begin, end)
        },
        toLastPage(val) {
            this.page = val;
            this.getCurrentPageData()
        },
        toFirstPage(val) {
            this.page = val;
            this.getCurrentPageData()
        },
        handleCurrentChange(val) {
            this.page = val;
            this.getCurrentPageData(val)
        },
        addApprover(){
            console.log(111111);
            this.multipleSelection;
            this.multipleSelection.forEach((items)=>{
                if(this.multipleSelection.length>1){
                    this.myData.Approver+=items.name+";"
                }else{
                    this.myData.Approver+=items.name
                }
            })
            this.dialogVisible = false
            
        },
        stepSave(){
           
            this.$store.dispatch("stepSave",this.myData)
            // console.log(this.$store.state.workFlow.stepManagement);
            this.$router.push("/stepManagement")
            
        }
    },
    created() {
        this.tableData = this.$store.state.workFlow.approverList
        this.lastPage = Math.ceil(this.tableData.length / this.limit)
        this.total = this.tableData.length
        this.getCurrentPageData();
        
    }



}
</script>


<style scoped>
.label-text {
    font-weight: 700;
    font-size: 14px;
    color: #333;
}

.sub-btn {
    margin-top: 20px;
    text-align: left;
}

.search {
    display: flex;
    justify-content: space-between;
}

.search-box {
    width: 151px;
}
</style>